package com.qf.lanzhou.blog.api.controller;

import com.alibaba.fastjson.JSON;
import com.qf.lanzhou.blog.api.pojo.entity.Praise;
import com.qf.lanzhou.blog.api.service.PraiseCountService;
import com.qf.lanzhou.blog.api.service.impl.PraiseCountServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author jian   点赞数统计
 * @Date 2020/12/17 15:25
 * @JDK 1.8
 * @Version 1.0
 */
@WebServlet("/count.do")
public class PraiseCountServlet extends BaseServletPost{
    private PraiseCountService praiseCountService=new PraiseCountServiceimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决请求的乱码
        req.setCharacterEncoding("utf-8");
        //解决响应乱码
        resp.setContentType("text/html;charset=utf-8");

        //获取参数(统计每篇文章的数量,状态值为1)
        String articleId = req.getParameter("articleId");
        String praiseStatus = req.getParameter("praiseStatus");

        Praise praise = praiseCountService.select(articleId, praiseStatus);
        String count = praise.getCount();
        successResultWrite(count,resp);
        //String json = JSON.toJSONString(count);
        //把点赞数写回前端
       // resp.getWriter().write(json);
    }
}
